package parcview.simulation;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Canvas;
import parcview.interfaces.CarIF;

public class Car implements CarIF {
	
	private static int count = 0;
	private long timeToLeave;
	private int ID;
	private Integer x;
        private Integer y;	
	
	public Car() {
		this.ID = count++;
		this.timeToLeave = 0;
	}

	@Override
	public int getID() {
		return this.ID;
	}

	@Override
	public long getTimeToLeave() {		
		return this.timeToLeave;
	}	
	
	public String toString() {
		return "Auto"+(this.ID);
	}

	@Override
	public void setTimeToLeave(long time) {
		this.timeToLeave = time;
	}
	
	
        public void setPos(Integer x, Integer y) {
            this.x = x;
            this.y = y;
        }
        
        public static void resetID() {
            Car.count = 0;
        }

        public void drawCar(GC g, Canvas d) {
            if(x != null && y != null) {
                g.setBackground(d.getDisplay().getSystemColor(SWT.COLOR_BLUE));
                g.setForeground(d.getDisplay().getSystemColor(SWT.COLOR_WHITE));
//                g.setBackground(d.getDisplay().getSystemColor(SWT.COLOR_BLUE));      
//                g.fillRectangle(x.intValue(), y.intValue(), 10, 10);
//                g.setBackground(d.getDisplay().getSystemColor(SWT.COLOR_WHITE)); 
//                g.setForeground(d.getDisplay().getSystemColor(SWT.COLOR_BLACK));
                g.drawText(((Integer)this.ID).toString(), x.intValue(), y.intValue()-15);
                d.redraw();
            }
        }
}
